﻿	      <?php include("conn.php");
             mysql_query('SET NAMES UTF8'); 

	  

class MyPrizeBean
{
	public $title;
	public $price;
	public $images;
	public $yuanjia;
	public $goodsid;
	public $reply;
	public $xihuan;
	public $summary;
   public $distance;
    public $shuliang;
	function __construct($title,$price,$images,$yuanjia,$goodsid,$reply,$xihuan,$summary,$distance,$shuliang)
	{
		$this->title      = $title;
		$this->price = $price;
		$this->images     = $images;
		$this->yuanjia      = $yuanjia;
		$this->goodsid    = $goodsid;
		$this->reply    = $reply;
		$this->xihuan    = $xihuan;
		$this->summary    = $summary;
		$this->distance    = $distance;
		$this->shuliang    = $shuliang;
	}
}

if($_REQUEST['page']!="")
{
$de=$_REQUEST['page']*$_REQUEST['pagesize'];
$size=$_REQUEST['pagesize'];
}

else
{
$de=0;
$size=5;
}

	$prize = array();


$sj=1;


	
//$query="select * from goods where  shangjia='".$sj."' and zixilie like '".$_REQUEST[fenlei]."%' and  city = '".$_REQUEST['city']."' order by  goodsid desc limit $de,$size"; 
$query="SELECT * FROM goods WHERE  city=$_REQUEST[city]  AND  zixilie  like '".$_REQUEST[fenlei]."%'  ORDER BY  goodsid DESC limit $de,$size";
    
	/*if($_REQUEST[zifenlei]!=""){

$s=" zixilie like '".$_REQUEST[zifenlei]."%'"; 

   $query =  $query." and $s";
} */



$rert=mysql_query($query);
	



	   function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
    $theta = $longitude1 - $longitude2;
    $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $miles = acos($miles);
    $miles = rad2deg($miles);
    $miles = $miles * 60 * 1.1515;
    $kilometers = $miles * 1.609344;
    return compact('kilometers'); 

}
	while($rowf=mysql_fetch_array($rert)){
	
	
	       
		        $rert32=mysql_query("select *from user where userid='".$_REQUEST[userid]."'");
     $rowf3=mysql_fetch_array($rert32);
     
       $longitude1=$rowf3['longitude'];$latitude1=$rowf3['latitude'];$longitude2=$rowf['longitude'];$latitude2=$rowf['latitude'];
	   



$distance = getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2);
foreach ($distance as $unit => $value) {
    $dic= number_format($value,1);
}

if($_REQUEST[userid]!="")
{
$juli=$dic;
}
else
{
$juli=0;
}


	$counts=mysql_query("select SUM(service) from goodsreply  where   goodsid ='".$rowf['goodsid']."'");

//评论数
$rss=mysql_fetch_array($counts);
$sum=$rss[0];






$count=mysql_query("select count(*) from goodsreply  where   goodsid ='".$rowf['goodsid']."'");

//评论数
$rs=mysql_fetch_array($count);
$totalNumber=$rs[0];
if ($totalNumber==0) {
	$ping=0;
}else{
	$ping=round(($sum/$totalNumber),2);
}


	if($totalNumber!=0)
{
$sum=$totalNumber;
$ping=round(($sum/$totalNumber),2);
}
else
{
$ping=5;

}


if ($ping < 2) {
                            $pinfen = "<span></span><span class='empty'></span><span class='empty'></span><span class='empty'></span><span class='empty'></span>";
                        } 
						
						 else if ($ping < 3 and $ping > 2) {
                            $pinfen = "<span></span><span></span><span class='empty'></span><span class='empty'></span><span class='empty'></span>";
                        } 
						
						 else if ($ping < 4 and $ping > 3) {
                           $pinfen = "<span></span><span></span><span ></span><span class='empty'></span><span class='empty'></span>";
                        }
						 else if ($ping < 5 and $ping > 4) {
                           $pinfen = "<span></span><span></span><span ></span><span></span><span class='empty'></span>";
                        }
						 else  {
                           $pinfen = "<span></span><span></span><span ></span><span ></span><span ></span>";
                        }
						
	$ime=$rowf[images];
				$de = array();
				$de=explode("," ,$ime);
				$imagesd=$de[0];
				
				 if(strlen($rowf['title'])>14)
		
		{
		
		$titles=mb_substr($rowf['title'], 0,14,"UTF-8");
		}
		else
		{
		$titles=$rowf['title'];
		}
		
		if(strlen($rowf['summary'])>30)
		
		{
		
		$summarys=mb_substr($rowf['summary'], 0,30,"UTF-8");
		}
		else
		{
		$summarys=$rowf['summary'];
		}
		
				

	$prize[] = new MyPrizeBean($titles,$rowf['price'],$imagesd,$rowf['yuanjia'],$rowf['goodsid'],$totalNumber,$rowf['xihuan'],$summarys,$juli,$rowf['xiaoliang']);
		
	}

echo json_encode($prize);


?>